package ping.pay.me.activity;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import ping.pay.me.R;
import ping.pay.me.common.UserStatus;
import ping.pay.me.framents.LoginFailFragment;
import ping.pay.me.framents.LoginSuccessFragment;

/**
 * Created by install on 14/12/14.
 */
public class UserCenterActivity extends Activity {

    private static UserStatus status = UserStatus.NOT_LOGIN;
    private LoginFailFragment frgFail = new LoginFailFragment();
    private LoginSuccessFragment frgSuccess = new LoginSuccessFragment();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_center_activity);


        FragmentManager frgMgr = getFragmentManager();
        FragmentTransaction frgTrans = frgMgr.beginTransaction();
        if(savedInstanceState == null) {
            frgTrans.add(R.id.home_page_container, frgFail);
            frgTrans.add(R.id.home_page_container,frgSuccess);

            if(status == UserStatus.LOGIN){
                frgTrans.show(frgSuccess);
                frgTrans.hide(frgFail);
            }else{
                frgTrans.show(frgFail);
                frgTrans.hide(frgSuccess);
            }
            frgTrans.commit();
        }
    }

    public void setStatus(UserStatus status){
        this.status = status;
    }

    public void setFragment(){
        FragmentManager frgMgr = getFragmentManager();
        FragmentTransaction frgTrans = frgMgr.beginTransaction();
        if(!frgFail.isAdded()) {
            frgTrans.add(R.id.home_page_container, frgFail);
        }
        if(!frgSuccess.isAdded()) {
            frgTrans.add(R.id.home_page_container, frgSuccess);
        }
        if(status == UserStatus.LOGIN){
            frgTrans.show(frgSuccess);
            frgTrans.hide(frgFail);
        }else{
            frgTrans.show(frgFail);
            frgTrans.hide(frgSuccess);
        }
        frgTrans.commit();
    }
}